import java.util.Vector;

public class MissingFinder {

	public static void main(String[] args) {
		Integer[] a = new Integer[] {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12};

		MissingFinder finder = new MissingFinder();
		int missingVal = finder.findMissing(a);

		System.out.println(missingVal);
	}

	public int findMissing(Integer[] a) {
		if (a == null || a.length == 0)
			return -1;
		Vector<Integer> v = new Vector<Integer>();
		for (Integer num : a) {
			v.add(num);
		}

		return findMissing(v, 0);
	}

	private int findMissing(Vector<Integer> a, int col) {
		if (col == Integer.SIZE) {
			return 0;
		}

		Vector<Integer> c0 = new Vector<Integer>();
		Vector<Integer> c1 = new Vector<Integer>();

		for (int i : a) {
			if (fetch(i, col))
				c1.add(i);
			else
				c0.add(i);
		}

		if (c0.size() <= c1.size()) {
			int v = findMissing(c0, col + 1);
			return (v << 1) | 0;
		} else {
			int v = findMissing(c1, col + 1);
			return (v << 1) | 1;
		}
	}

	public boolean fetch(int num, int j) {
		return (num & (1 << j)) != 0;
	}
}
